var PageStatKey = "www.taosijie.com.chrometool.PageStatSwitch";
var DebugKey = "www.taosijie.com.chrometool.DebugSwitch";
var AutoClickKey = "www.taosijie.com.chrometool.AutoClickSwitch";

// 开关界面变化
function ChangeSwitchStatus(switchele){
    var imgdiv = switchele.children[0];
    var childstrong = switchele.children[1].children[0].children[0];
    if(imgdiv && childstrong){
        if(imgdiv.className == "switchitemimgsel"){
            imgdiv.className = "switchitemimgnosel";
            childstrong.innerText = "关闭";
            return "close";
        }else if(imgdiv.className == "switchitemimgnosel"){
            imgdiv.className = "switchitemimgsel";
            childstrong.innerText = "开启";
            return "open";
        }
    }
    return null;
}

// 获取本地存储值
function GetLocalStorageValue(key){
    if(window.localStorage){
        var value = window.localStorage.getItem(key);
        return value;
    }
    return null;
}

// 设置本地存储
function SetLocalStorageValue(key, value){
    if(window.localStorage){
        var value = window.localStorage.setItem(key, value);
    }
}

// 界面点击事件以及初始化界面显示
// 页面统计开关
var statswitch = document.getElementById("pagestatswitch");
statswitch.onclick = function(){
    var SwitchValue = ChangeSwitchStatus(statswitch);
    // 更新配置至本地存储
    SetLocalStorageValue(PageStatKey, SwitchValue);
}
// debug日志开关
var debugswitch = document.getElementById("debugswitch");
debugswitch.onclick = function(){
    var SwitchValue = ChangeSwitchStatus(debugswitch);
    // 更新配置至本地存储
    SetLocalStorageValue(DebugKey, SwitchValue);
}
// 自动点击开关
var autoclickswitch = document.getElementById("autoclickswitch");
autoclickswitch.onclick = function(){
    var SwitchValue = ChangeSwitchStatus(autoclickswitch);
    // 更新配置至本地存储
    SetLocalStorageValue(AutoClickKey, SwitchValue);
}

// 根据配置调整下界面
// 默认开启
if(GetLocalStorageValue(PageStatKey) == "close"){
    ChangeSwitchStatus(statswitch);
}
// 默认关闭
if(GetLocalStorageValue(DebugKey) == "open"){
    ChangeSwitchStatus(debugswitch);
}
// 默认关闭
if(GetLocalStorageValue(AutoClickKey) == "open"){
    ChangeSwitchStatus(autoclickswitch);
}

